@extends('layouts.layout')

@section('header')

    <title>商品详情</title>

    <link rel="stylesheet" type="text/css" href="{{URL::asset('static/css/goods_info.css')}}"/>

@endsection

@section('content')
        <div class="box">
            <img src="img/info.jpg" alt="">
            <p>面膜面膜</p>
            <span>￥56</span>
        </div>
        <div class="banner">
            <div class="tit">
                商品详情
            </div>
            <div class="details">

            </div>
        </div>


        <div class="footer">
            <div class="addBox">
                <span class="reduce">-</span>
                <i>1</i>盒
                <span class="add">+</span>
            </div>
            <div>
                <p class="btn">立即购买</p>
            </div>
        </div>


@endsection

@section('script')
    <script type="text/javascript">
       $(function(){
           // 获取商品信息
           var info = JSON.parse(sessionStorage.getItem('goodsInfo'))

           $(".box img").attr('src','/uploads/'+info.goods_cover)
           $(".box p").html(info.goods_name)
           $(".box span").html('￥'+info.goods_prices)
           var str = ""
           var arr = info.pictures
           arr.forEach(function(item,index){
               str += '<img src="/uploads/'+item+'" alt="">'
           })
           $('.details').empty().append(str)

           $(".reduce").click(function(){
               if($('.addBox i').text() == 1){
                   return false;
               }
               $('.addBox i').html($('.addBox i').text() - 1)
           })
           $(".add").click(function(){
               $('.addBox i').html(parseInt($('.addBox i').text()) + 1)
           })
           $('.footer .btn').click(function(){
               var num = $(".addBox i").html();
               info['num'] = num;
               sessionStorage.setItem('goodsInfo',JSON.stringify(info))
           	window.location.href = "/order/submit/"
           })
       })
    </script>

@endsection
